home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / vlapak1.zip / VLAMODEX.ZIP / MODEX.INC < prev    next >
Text File  |  1993-05-10  |  17KB  |  586 lines

  1. ;
  2. ;  Here is my latest collection of routines for the infamous X-Mode.
  3. ;  I thought I'd release it, cause I'm just such a nice guy. =)
  4. ;  
  5. ;  If ya want to create different modes, it's basically just cut-and-paste.
  6. ;
  7. ;  May this code make your assembler programs as smooth as Lime Jello. 
  8. ;
  9. ;*  Questions, Comments? E-mail draeden@u.washington.edu (that's me!)  *
  10. ;
  11. ;   Draeden /VLA
  12. ;─────
  13.  
  14. LABEL X320Y200 word 
  15.     db      00      ; 0e3h    ; dot clock
  16.     db      02      ; Number of CRTC Registers to update
  17.     dw      00014h  ; turn off dword mode
  18.     dw      0e317h  ; turn on byte mode
  19.     dw      320     ; width
  20.     dw      200     ; height
  21.  
  22. LABEL X320Y240 word
  23.     db      0e3h    ; dot clock
  24.     db      10      ; Number of CRTC Registers to update
  25.     dw      00d06h  ; vertical total
  26.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  27.     dw      04109h  ; cell height (2 to double-scan)
  28.     dw      0ea10h  ; v sync start
  29.     dw      0ac11h  ; v sync end and protect cr0-cr7
  30.     dw      0df12h  ; vertical displayed
  31.     dw      00014h  ; turn off dword mode
  32.     dw      0e715h  ; v blank start
  33.     dw      00616h  ; v blank end
  34.     dw      0e317h  ; turn on byte mode
  35.     dw      320     ; width
  36.     dw      240     ; height
  37.  
  38. LABEL X360Y200 word
  39.     db      0e7h    ; dot clock
  40.     db      08      ; Number of CRTC Registers to update
  41.     dw      06b00h  ; horz total
  42.     dw      05901h  ; horz displayed
  43.     dw      05a02h  ; start horz blanking
  44.     dw      08e03h  ; end horz blanking
  45.     dw      05e04h  ; start h sync
  46.     dw      08a05h  ; end h sync
  47.     dw      00014h  ; turn off dword mode
  48.     dw      0e317h  ; turn on byte mode
  49.     dw      360     ; width
  50.     dw      200     ; height
  51.  
  52. LABEL X360Y240 word
  53.     db      0e7h    ; dot clock
  54.     db      16      ; Number of CRTC Registers to update
  55.     dw      06b00h  ; horz total
  56.     dw      05901h  ; horz displayed
  57.     dw      05a02h  ; start horz blanking
  58.     dw      08e03h  ; end horz blanking
  59.     dw      05e04h  ; start h sync
  60.     dw      08a05h  ; end h sync
  61.     dw      00d06h  ; vertical total
  62.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  63.     dw      04109h  ; cell height (2 to double-scan)
  64.     dw      0ea10h  ; v sync start
  65.     dw      0ac11h  ; v sync end and protect cr0-cr7
  66.     dw      0df12h  ; vertical displayed
  67.     dw      00014h  ; turn off dword mode
  68.     dw      0e715h  ; v blank start
  69.     dw      00616h  ; v blank end
  70.     dw      0e317h  ; turn on byte mode
  71.     dw      360
  72.     dw      240
  73.  
  74. LABEL X376Y282 word
  75.     db      0e7h
  76.     db      18
  77.     dw      06e00h  ; horz total
  78.     dw      05d01h  ; horz displayed
  79.     dw      05e02h  ; start horz blanking
  80.     dw      09103h  ; end horz blanking
  81.     dw      06204h  ; start h sync
  82.     dw      08f05h  ; end h sync
  83.     dw      06206h  ; vertical total
  84.     dw      0f007h  ; overflow
  85.     dw      06109h  ; cell height
  86.     dw      0310fh  ;
  87.     dw      03710h  ; v sync start
  88.     dw      08911h  ; v sync end and protect cr0-cr7
  89.     dw      03312h  ; vertical displayed
  90.     dw      02f13h  ; offset
  91.     dw      00014h  ; turn off dword mode
  92.     dw      03c15h  ; v blank start
  93.     dw      05c16h  ; v blank end
  94.     dw      0e317h  ; turn on byte mode
  95.     dw      376
  96.     dw      564
  97.  
  98. LABEL X320Y400 word
  99.     db      0e3h    ; dot clock
  100.     db      03      ; Number of CRTC Registers to update
  101.     dw      04009h  ; cell height
  102.     dw      00014h  ; turn off dword mode
  103.     dw      0e317h  ; turn on byte mode
  104.     dw      320     ; width
  105.     dw      400     ; height
  106.  
  107. LABEL X320Y480 word
  108.     db      0e3h    ; dotclock
  109.     db      10      ; Number of CRTC Registers to update
  110.     dw      00d06h  ; vertical total
  111.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  112.     dw      04009h  ; cell height (2 to double-scan)
  113.     dw      0ea10h  ; v sync start
  114.     dw      0ac11h  ; v sync end and protect cr0-cr7
  115.     dw      0df12h  ; vertical displayed
  116.     dw      00014h  ; turn off dword mode
  117.     dw      0e715h  ; v blank start
  118.     dw      00616h  ; v blank end
  119.     dw      0e317h  ; turn on byte mode
  120.     dw      320     ; width
  121.     dw      480     ; height
  122.  
  123. LABEL X360Y400 word
  124.     db      0e7h    ; dot clock
  125.     db      09      ; Number of CRTC Registers to update
  126.     dw      06b00h  ; horz total
  127.     dw      05901h  ; horz displayed
  128.     dw      05a02h  ; start horz blanking
  129.     dw      08e03h  ; end horz blanking
  130.     dw      05e04h  ; start h sync
  131.     dw      08a05h  ; end h sync
  132.     dw      04009h  ; cell height
  133.     dw      00014h  ; turn off dword mode
  134.     dw      0e317h  ; turn on byte mode
  135.     dw      360     ; width
  136.     dw      400     ; height
  137.  
  138.  
  139. LABEL X360Y480 word
  140.     db      0e7h
  141.     db      17
  142.     dw      06b00h  ; horz total
  143.     dw      05901h  ; horz displayed
  144.     dw      05a02h  ; start horz blanking
  145.     dw      08e03h  ; end horz blanking
  146.     dw      05e04h  ; start h sync
  147.     dw      08a05h  ; end h sync
  148.     dw      00d06h  ; vertical total
  149.     dw      03e07h  ; overflow
  150.     dw      04009h  ; cell height
  151.     dw      0ea10h  ; v sync start
  152.     dw      0ac11h  ; v sync end and protect cr0-cr7
  153.     dw      0df12h  ; vertical displayed
  154.     dw      02d13h  ; offset
  155.     dw      00014h  ; turn off dword mode
  156.     dw      0e715h  ; v blank start
  157.     dw      00616h  ; v blank end
  158.     dw      0e317h  ; turn on byte mode
  159.     dw      360
  160.     dw      480
  161.  
  162. LABEL X360Y360 word
  163.     db      0e7h
  164.     db      15
  165.     dw      06b00h  ; horz total
  166.     dw      05901h  ; horz displayed
  167.     dw      05a02h  ; start horz blanking
  168.     dw      08e03h  ; end horz blanking
  169.     dw      05e04h  ; start h sync
  170.     dw      08a05h  ; end h sync
  171.     dw      04009h  ; cell height
  172.     dw      08810h  ; v sync start
  173.     dw      08511h  ; v sync end and protect cr0-cr7
  174.     dw      06712h  ; vertical displayed
  175.     dw      02d13h  ; offset
  176.     dw      00014h  ; turn off dword mode
  177.     dw      06d15h  ; v blank start
  178.     dw      0ba16h  ; v blank end
  179.     dw      0e317h  ; turn on byte mode
  180.     dw      360
  181.     dw      360
  182.  
  183. LABEL X376Y308 word
  184.     db      0e7h
  185.     db      18
  186.     dw      06e00h  ; horz total
  187.     dw      05d01h  ; horz displayed
  188.     dw      05e02h  ; start horz blanking
  189.     dw      09103h  ; end horz blanking
  190.     dw      06204h  ; start h sync
  191.     dw      08f05h  ; end h sync
  192.     dw      06206h  ; vertical total
  193.     dw      00f07h  ; overflow
  194.     dw      04009h  ;
  195.     dw      0310fh  ;
  196.     dw      03710h  ; v sync start
  197.     dw      08911h  ; v sync end and protect cr0-cr7
  198.     dw      03312h  ; vertical displayed
  199.     dw      02f13h  ; offset
  200.     dw      00014h  ; turn off dword mode
  201.     dw      03c15h  ; v blank start
  202.     dw      05c16h  ; v blank end
  203.     dw      0e317h  ; turn on byte mode
  204.     dw      376
  205.     dw      308
  206.  
  207. LABEL X376Y564 word
  208.     db      0e7h
  209.     db      18
  210.     dw      06e00h  ; horz total
  211.     dw      05d01h  ; horz displayed
  212.     dw      05e02h  ; start horz blanking
  213.     dw      09103h  ; end horz blanking
  214.     dw      06204h  ; start h sync
  215.     dw      08f05h  ; end h sync
  216.     dw      06206h  ; vertical total
  217.     dw      0f007h  ; overflow
  218.     dw      06009h  ;
  219.     dw      0310fh  ;
  220.     dw      03710h  ; v sync start
  221.     dw      08911h  ; v sync end and protect cr0-cr7
  222.     dw      03312h  ; vertical displayed
  223.     dw      02f13h  ; offset
  224.     dw      00014h  ; turn off dword mode
  225.     dw      03c15h  ; v blank start
  226.     dw      05c16h  ; v blank end
  227.     dw      0e317h  ; turn on byte mode
  228.     dw      376
  229.     dw      564
  230.     
  231. LABEL X256Y240 word
  232.     db      0e3h    ; dot clock
  233.     db      16      ; Number of CRTC Registers to update
  234.     dw      05f00h  ; horz total
  235.     dw      03f01h  ; horz displayed
  236.     dw      04202h  ; start horz blanking
  237.     dw      09f03h  ; end horz blanking
  238.     dw      04c04h  ; start h sync
  239.     dw      00005h  ; end h sync
  240.     dw      00d06h  ; vertical total
  241.     dw      03e07h  ; overflow (bit 8 of vertical counts)
  242.     dw      04109h  ; cell height (2 to double-scan)
  243.     dw      0ea10h  ; v sync start
  244.     dw      0ac11h  ; v sync end and protect cr0-cr7
  245.     dw      0df12h  ; vertical displayed
  246.     dw      00014h  ; turn off dword mode
  247.     dw      0e715h  ; v blank start
  248.     dw      00616h  ; v blank end
  249.     dw      0e317h  ; turn on byte mode
  250.     dw      256
  251.     dw      240
  252.     
  253. LABEL X256Y200 word
  254.     db      0e3h    ; dot clock
  255.     db      8       ; Number of CRTC Registers to update
  256.     dw      05f00h  ; horz total
  257.     dw      03f01h  ; horz displayed
  258.     dw      04202h  ; start horz blanking
  259.     dw      09f03h  ; end horz blanking
  260.     dw      04c04h  ; start h sync
  261.     dw      00005h  ; end h sync
  262.     dw      00014h  ; turn off dword mode
  263.     dw      0e317h  ; turn on byte mode
  264.     dw      256
  265.     dw      200
  266.     
  267. LAST_X_MODE         =     13
  268.  
  269. LABEL ModeTable word    ; Mode X tweak table
  270.     dw      offset X320Y200
  271.     dw      offset X320Y240
  272.     dw      offset X360Y200
  273.     dw      offset X360Y240
  274.     dw      offset X376Y282
  275.     dw      offset X320Y400
  276.     dw      offset X320Y480
  277.     dw      offset X360Y400
  278.     dw      offset X360Y480
  279.     dw      offset X360Y360
  280.     dw      offset X376Y308
  281.     dw      offset X376Y564
  282.     dw      offset X256Y240
  283.     dw      offset x256y200
  284.     
  285. M320x200x256 =0     ;constants for easy calling
  286. M320x240x256 =1
  287. M360x200x256 =2
  288. M360x240x256 =3
  289. M376x282x256 =4
  290. M320x400x256 =5
  291. M320x480x256 =6
  292. M360x400x256 =7
  293. M360x480x256 =8
  294. M360x360x256 =9
  295. M376x308x256 =10
  296. M376x564x256 =11
  297. M256x240x256 =12    ;GREAT modes - ypos is upper byte, xpos is lower
  298. M256x200x256 =13
  299.  
  300. InputStatus1=   3dah
  301. MISC_OUTPUT =   3c2h
  302. SC_Index    =   3c4h
  303. CRTC_Index  =   3d4h
  304. Graph_Index =   3ceh
  305. Attr_Index  =   3c0h    ;don't forget to clear flipflop & set bit 5 on index
  306. PEL_Write   =   3c8h
  307. PEL_Read    =   3c7h
  308. PEL_Data    =   3c9h
  309.  
  310. VGASeg      dw  0a000h
  311. ModeXScanLines dw 0
  312. ModeXWidth  dw  0
  313. ModeXHeight dw  0
  314.  
  315. ;-----------------------------------------------------------------------
  316. ;
  317. ;   Sets mode # in AX, returns ax=0 if successful, ax=-1 if failed
  318. ;   cx= width of screen 
  319. ;
  320. ; SetModeX Adapted for VLA by Draeden,
  321. ; who leached it out of XLIB04C which was
  322. ; originally written by Themie Gouthas,
  323. ; who adapted parts from M. Abrash code.
  324. ; (Talk about code reuse!)
  325. ;------------------------------------------------------------------------
  326. _Mode   dw  0
  327. _Scrw   dw  0
  328.  
  329. MACRO @SetModeX DaMode,DaWidth
  330.     mov     ax,DaMode
  331.     mov     cx,DaWidth
  332.     call    _Set_X_Mode
  333. ENDM @SetModeX
  334.  
  335. PROC _Set_X_Mode NEAR
  336.     pusha
  337.     push    es ds
  338.  
  339.     cld
  340.     mov     bx,cs
  341.     mov     ds,bx
  342.     mov     es,bx
  343.  
  344.     cmp     ax,LAST_X_MODE      ; have we selected a valid mode?
  345.     jle     @@ValidMode         ; Yes !
  346.  
  347.     pop     ds es
  348.     popa
  349.     mov     ax,-1               ; idiot.
  350.     ret
  351.  
  352. @@ValidMode:
  353.     mov     [_Mode],ax
  354.     mov     [_Scrw],cx
  355.  
  356.     mov     ax,13h              ; let the BIOS set standard 256-color
  357.     int     10h                 ;  mode (320x200 linear)
  358.     
  359.     mov     dx,SC_INDEX
  360.     mov     ax,0604h
  361.     out     dx,ax               ; disable chain4 mode
  362.     mov     ax,0100h
  363.     out     dx,ax               ; synchronous reset while setting Misc
  364.                                 ;  Output for safety, even though clock
  365.                                 ;  unchanged
  366.     mov     bx,[_Mode]
  367.     add     bx,bx
  368.     mov     si,[bx + ModeTable]
  369.     lodsb
  370.  
  371.     or      al,al
  372.     jz      @@DontSetDot
  373.     mov     dx,MISC_OUTPUT
  374.     out     dx,al               ; select the dot clock and Horiz
  375.                                 ;  scanning rate
  376. @@DontSetDot:
  377.     mov     dx,SC_INDEX
  378.     mov     ax,0300h
  379.     out     dx,ax               ; undo reset (restart sequencer)
  380.  
  381.     mov     dx,CRTC_INDEX       ; reprogram the CRT Controller
  382.     mov     al,11h              ; VSync End reg contains register write
  383.     out     dx,al               ; protect bit
  384.     inc     dx                  ; CRT Controller Data register
  385.     in      al,dx               ; get current VSync End register setting
  386.     and     al,07fh             ; remove write protect on various
  387.     out     dx,al               ; CRTC registers
  388.     dec     dx                  ; CRT Controller Index
  389.     cld
  390.     xor     cx,cx
  391.     lodsb
  392.     mov     cl,al
  393.  
  394. @@SetCRTParmsLoop:
  395.     lodsw                       ; get the next CRT Index/Data pair
  396.     out     dx,ax               ; set the next CRT Index/Data pair
  397.     dec     cx
  398.     jne     @@SetCRTParmsLoop
  399.  
  400.     lodsw
  401.     mov     [cs:ModeXWidth],ax
  402.     lodsw
  403.     mov     [cs:ModeXHeight],ax
  404.     cmp     ax,240
  405.     jg      @@DontDouble
  406.     add     ax,ax
  407. @@DontDouble:
  408.     mov     [cs:ModeXScanLines],ax
  409.  
  410.     mov     dx,SC_INDEX
  411.     mov     ax,0f02h
  412.     out     dx,ax               ; enable writes to all four planes
  413.  
  414.                                 ; now clear all display memory, 8 pixels
  415.     mov     es,[cs:VGAseg]      ; at a time
  416.     sub     di,di               ; point ES:DI to display memory
  417.     sub     ax,ax               ; clear to zero-value pixels
  418.     mov     cx,8000h            ; # of words in display memory
  419.     rep     stosw               ; clear all of display memory
  420.     
  421.     ;  Mode X is set, now set the required logical page width.
  422.  
  423.     mov     cx,[cs:_Scrw]
  424.     shr     cx,3            ;divide by 8
  425.     mov     dx,CRTC_INDEX
  426.     mov     al,13h
  427.     mov     ah,cl
  428.     out     dx,ax
  429.  
  430.     pop     ds es
  431.     popa
  432.     xor     ax,ax
  433.     ret
  434. ENDP _Set_X_Mode
  435.  
  436. ────────────────────────────────────────────────────────────────────────────
  437. ;*   MISC planar mode routines - Written by Draeden /VLA
  438. ────────────────────────────────────────────────────────────────────────────
  439.  
  440.     ;ah: 0000b : bit 0= plane 0, bit 1=plane 1, etc..
  441.     ;
  442.     ;DESTROYS: al, dx
  443.     ;
  444. MACRO  @Set_Write_Plane
  445.     mov     dx,SC_Index
  446.     mov     al,2
  447.     and     ah,1111b
  448.     out     dx,ax
  449. ENDM   @Set_Write_Plane
  450.  
  451.     ;ah: plane to latch for read (0-3)
  452.     ;
  453.     ;DESTROYS: al, dx
  454.     ;
  455. MACRO  @Set_Read_Plane
  456.     mov     dx,Graph_Index
  457.     mov     al,4
  458.     out     dx,ax
  459. ENDM   @Set_Read_Plane
  460.  
  461.     ;ah: write mode (0-3)
  462.     ;
  463.     ;DESTROYS: ax, dx
  464.     ;
  465. MACRO @Set_Write_Mode
  466.     mov     dx,Graph_Index
  467.     mov     al,5
  468.     out     dx,al
  469.     inc     dx
  470.     in      al,dx
  471.     and     al,11111100b    ;clear out write mode bits
  472.     and     ah,00000011b
  473.     or      al,ah
  474.     out     dx,al
  475. ENDM  @Set_Write_Mode
  476.  
  477.     ;ah: Read mode (0-1)
  478.     ;
  479.     ;DESTROYS: ax, dx
  480.     ;
  481. MACRO @Set_Read_Mode
  482.     mov     dx,Graph_Index
  483.     mov     al,5
  484.     out     dx,al
  485.     inc     dx
  486.     in      al,dx
  487.     and     al,11110111b    ;clear out write mode bits
  488.     shl     ah,3            ;move bit to correct position
  489.     and     ah,00001000b
  490.     or      al,ah
  491.     out     dx,al
  492. ENDM  @Set_Read_Mode
  493.  
  494.     ;bx: starting offset
  495.     ;
  496.     ;DESTROYS: ax, dx
  497.     ;
  498. MACRO @Set_Start_Offset
  499.     mov     dx,CRTC_Index
  500.     mov     al,0ch
  501.     mov     ah,bh       ;write the HIGH byte
  502.     out     dx,ax
  503.     inc     al
  504.     mov     ah,bl       ;write the LOW byte
  505.     out     dx,ax
  506. ENDM  @Set_Start_Offset
  507.  
  508.     ;bx: scanline to set split screen at
  509.     ;
  510.     ;DESTROYS: ax, dx
  511.     ;
  512. MACRO @Set_Split
  513.     mov     al,18h
  514.     mov     ah,bl
  515.     mov     dx,CRTC_Index
  516.     out     dx,ax       ;set bits 0-7
  517.  
  518.     mov     al,09h
  519.     out     dx,al
  520.     inc     dx
  521.     in      al,dx
  522.     mov     ah,bh
  523.     and     ah,00000010b
  524.     shl     ah,5
  525.     and     al,10111111b
  526.     or      al,ah
  527.     out     dx,al       ;set bit 9
  528.  
  529.     dec     dx
  530.     mov     al,07h
  531.     out     dx,al
  532.     inc     dx
  533.     in      al,dx
  534.     and     al,11101111b
  535.     mov     ah,bh
  536.     and     ah,00000001b
  537.     shl     ah,4
  538.     or      al,ah
  539.     out     dx,al       ;set bit 8
  540. ENDM @Set_SPlit
  541.  
  542. MACRO @FullVertWait
  543.     mov     dx,InputStatus1
  544. @@VR:
  545.     in      al,dx
  546.     test    al,8
  547.     jnz     @@VR                    ;wait until Verticle Retrace starts
  548. @@NVR:
  549.     in      al,dx
  550.     test    al,8
  551.     jz      @@NVR                   ;wait until Verticle Retrace Ends
  552. ENDM @FullVertWait
  553.  
  554. MACRO @WaitVert
  555.     mov     dx,InputStatus1
  556. @@VR:
  557.     in      al,dx
  558.     test    al,8
  559.     jnz     @@VR                    ;wait until Verticle Retrace starts
  560. ENDM  @WaitVert
  561.  
  562. MACRO @WaitVertEnd
  563.     mov     dx,InputStatus1
  564. @@NVR:
  565.     in      al,dx
  566.     test    al,8
  567.     jz      @@NVR                   ;wait until Verticle Retrace Ends
  568. ENDM  @WaitVertEnd
  569.     
  570.     ;si = offset to palette
  571.     ;cx = number of colors to write
  572.     ;al = starting palette register
  573.     ;
  574.     ;DESTROYS: dx,si,cx
  575.     ;
  576. MACRO @WritePalette
  577.     mov     dx,cx
  578.     add     cx,cx
  579.     add     cx,dx
  580.     mov     dx,03c8h
  581.     out     dx,al
  582.     inc     dx
  583.     cld
  584.     rep outsb
  585. ENDM @WritePalette
  586.